//
//  RCAppApi.m
//  FreshMember
//
//  Created by qyc on 2019/4/19.
//  Copyright © 2019年 qyc. All rights reserved.
//

#import "HAAppApi.h"
#import "HASessionApi.h"

@implementation HAAppApi

+ (HAAppApi *)sharedApi {
    static dispatch_once_t pred = 0;
    __strong static HAAppApi *_sharedApi = nil;
    dispatch_once(&pred, ^{
        _sharedApi = [[HAAppApi alloc] init];
    });
    return _sharedApi;
}

- (void)requestRiderUpVserionCompletionHandler:(AppApiSuccessHandler)completionHandler errorHandler:(AppApiErrorHandler)errorHandler {
    
    NSMutableDictionary *requestArgument = [[NSMutableDictionary alloc] initWithCapacity:10];
    
    HASessionApi *api = [[HASessionApi alloc] initSessionTaskWithRequestMethod:YTKRequestMethodPOST url:RIDERO_UPVISEION requestArgument:requestArgument];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        // 请求完成
        NSDictionary *responseJSONObject = request.responseJSONObject;
        
        if ([responseJSONObject[@"status"] integerValue] == HAUserAppApiWithMessageSuccess) {
            // 处理完成
            completionHandler(responseJSONObject[@"data"]);
        } else {
            
            [CustomProgressHUD showMessage:responseJSONObject[@"msg"] time:0];
            errorHandler(responseJSONObject[@"data"]);
        }
        
    } failure:^(YTKBaseRequest *request) {
        // 处理错误
        errorHandler(request.error);
    }];
}

@end
